
data_test<-read.csv("ISQ_Data_Triggers_of_MK.csv")
#set.seed(042902)

#Changing conflict conditions (Table 2)
#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-28] #Remove missing data (function does not have built-in listwise deletion)
countries<-countries[-129]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")



#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")
#Error means there are no observed mk_onset in democracy; recorded as 0

#CW 2
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
#countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")
#Error means there are no observed mk_onset in democracy; recorded as 0

#CW 3
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")
#Error means there are no observed mk_onset in democracy; recorded as 0

#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")
#Error means there are no observed mk_onset in democracy; recorded as 0

#CW 2
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")
#Error means there are no observed mk_onset in democracy; recorded as 0

#CW 3
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")
#Error means there are no observed mk_onset in democracy; recorded as 0


#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")
#Error means there are no observed mk_onset in democracy; recorded as 0

#CW 2 
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
#countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")
#Error means there are no observed mk_onset in democracy; recorded as 0

#CW 3
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
#countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")
#Error means there are no observed mk_onset in democracy; recorded as 0


#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-55]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-7]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-7]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-7]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-7]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-23]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-23]
countries<-countries[-106]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-23]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-23]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")



#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-24]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-24]
countries<-countries[-106]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-24]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-24]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")



#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
#countries<-countries[-24]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")



#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")



#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Popular civilian mobilization (Table 3)
#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-85] 
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-85]
countries<-countries[-130] 
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-85]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-85]
countries<-countries[-130]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Regime type
#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-31] 
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-59] 
countries<-countries[-31] 
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-31]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-59]
countries<-countries[-31]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
countries<-countries[-26]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-26]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-65] 
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
countries<-countries[-65] 
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-65]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-65]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
countries<-countries[-26] 
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-26]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
countries<-countries[-24] 
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-24]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-68]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
countries<-countries[-68] 
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-68]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-68]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
countries<-countries[-20] 
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-20]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
countries<-countries[-20] 
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-20]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
countries<-countries[-13] 
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-13]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
countries<-countries[-10] 
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-10]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Threats to leadership integrity (Table 4)
#Unsuccessful coup
data_test$unsuccessful_coup<-(-99)
data_test$unsuccessful_coup[data_test$pt_attempt==1 & data_test$pt_success==0]<-1
data_test$unsuccessful_coup[data_test$pt_attempt==0]<-0

#CW 1
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
data_test$pt_success[is.na(data_test$pt_success)]<-(-99)
#CW 1
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Unsuccessful coup
#CW 1
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
data_test$pt_success[is.na(data_test$pt_success)]<-(-99)
#CW 1
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Unsuccessful coup
#CW 1
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
#CW 1
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Unsuccessful coup
#CW 1
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
#CW 1
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Unsuccessful coup
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Successful coup
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Unsuccessful coup
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Unsuccessful coup
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Successful coup
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Unsuccessful coup
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Unsuccessful coup
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Unsuccessful coup
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Unsuccessful coup
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Unsuccessful coup
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Trigger combinations (Table 5)
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "combo__reb_deaths_civilians_escalation__gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$combo__reb_deaths_civilians_escalation__gov_battle_deaths_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "combo__reb_deaths_civilians_escalation__gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "combo__gov_battle_deaths_escalation__spillover", "mk_onset")]
t<-t[which(t$combo__gov_battle_deaths_escalation__spillover>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "combo__gov_battle_deaths_escalation__spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "combo__nonviolent_protest_escalation__gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$combo__nonviolent_protest_escalation__gov_battle_deaths_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "combo__nonviolent_protest_escalation__gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")



set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "combo__protesterviolence_escalation__gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$combo__protesterviolence_escalation__gov_battle_deaths_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "combo__protesterviolence_escalation__gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "combo__unsuccessful_coup__gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$combo__unsuccessful_coup__gov_battle_deaths_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "combo__unsuccessful_coup__gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "combo__pt_success__gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$combo__pt_success__gov_battle_deaths_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "combo__pt_success__gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")



set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "combo__reb_deaths_civilians_escalation__spillover", "mk_onset")]
t<-t[which(t$combo__reb_deaths_civilians_escalation__spillover>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "combo__reb_deaths_civilians_escalation__spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")



set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "combo__unsuccessful_coup__reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$combo__unsuccessful_coup__reb_deaths_civilians_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "combo__unsuccessful_coup__reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")



set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "combo__nonviolent_protest_escalation__reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$combo__nonviolent_protest_escalation__reb_deaths_civilians_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "combo__nonviolent_protest_escalation__reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "combo__protesterviolence_escalation__reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$combo__protesterviolence_escalation__reb_deaths_civilians_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "combo__protesterviolence_escalation__reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")



set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "combo__pt_success__reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$combo__pt_success__reb_deaths_civilians_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "combo__pt_success__reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")




set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "combo__nonviolent_protest_escalation__spillover", "mk_onset")]
t<-t[which(t$combo__nonviolent_protest_escalation__spillover>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "combo__nonviolent_protest_escalation__spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "combo__protesterviolence_escalation__spillover", "mk_onset")]
t<-t[which(t$combo__protesterviolence_escalation__spillover>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "combo__protesterviolence_escalation__spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")



table(data_test$combo__unsuccessful_coup__spillover)
table(data_test$combo__pt_success__spillover)
#No instances of successful coup co-occuring with spillover, record TCR as 0
#No instances of unsuccessful coup co-occuring with conflict spillover, record TCR as 0

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "combo__nonviolent_protest_escalation__protesterviolence_escalation", "mk_onset")]
t<-t[which(t$combo__nonviolent_protest_escalation__protesterviolence_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "combo__nonviolent_protest_escalation__protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "combo__unsuccessful_coup__nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$combo__unsuccessful_coup__nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "combo__unsuccessful_coup__nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "combo__pt_success__nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$combo__pt_success__nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "combo__pt_success__nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")



set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "combo__unsuccessful_coup__protesterviolence_escalation", "mk_onset")]
t<-t[which(t$combo__unsuccessful_coup__protesterviolence_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "combo__unsuccessful_coup__protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")



set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "combo__pt_success__protesterviolence_escalation", "mk_onset")]
t<-t[which(t$combo__pt_success__protesterviolence_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "combo__pt_success__protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

